<?php
/**
 * 73YC mobile首页文件
 * ============================================================================
 * * 版权所有 20013-* 梅州络客网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.alork.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liubo $
 * $Id: index.php 17217 2013-10-19 06:29:08Z liubo $
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}

assign_template();


$promote_goods = get_pre_order_goods();


$smarty->assign('expect_end_time', $expect_end_time);
$smarty->assign('expect_start_time', $expect_start_time);
$smarty->assign('promote_goods', $promote_goods);

$smarty->display("pre_order_test.dwt");




/**
 * 获得预购商品
 *
 * @access  public
 * @param   string  $children
 * @return  array
 */
function get_pre_order_goods(){
    $sql = 'SELECT po.pre_order_id, po.pre_order_num, po.limit_num, po.buy_num, po.buy_number, po.pre_order_part, po.start_time, po.end_time, po.pre_order_price, po.goods_sku, g.goods_id, g.goods_name, g.goods_sku, g.shop_price, g.goods_thumb, g.goods_img, gs.goods_number, gs.goods_sku, ga.goods_attr_id ' . 
        ' FROM ' . $GLOBALS['ecs']->table('pre_order') . ' AS po ' . 
        " LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g " . 
        " ON g.goods_sku = po.goods_sku " . 
        " LEFT JOIN " . $GLOBALS['ecs']->table('goods_stock') . " AS gs " . 
        " ON gs.goods_sku = po.goods_sku " . 
        " LEFT JOIN " . $GLOBALS['ecs']->table('goods_attr') . "AS ga " .
        " ON ga.goods_id = g.goods_id " . 
        " WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND gs.area_id = 3" . 
        " ORDER BY po.pre_order_id DESC";
    $res = $GLOBALS['db']->query($sql);
    
    $arr = array();
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $arr[$row['goods_id']]['goods_id']         = $row['goods_id'];
        $arr[$row['goods_id']]['goods_name']       = $row['goods_name'];
        $arr[$row['goods_id']]['shop_price']       = price_format($row['shop_price']);
        $arr[$row['goods_id']]['goods_thumb']      = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $arr[$row['goods_id']]['goods_img']        = get_image_path($row['goods_id'], $row['goods_img']);
        $arr[$row['goods_id']]['url']              = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
        $arr[$row['goods_id']]['pre_order_part']   = $row['pre_order_part']; //第几块区域
        $arr[$row['goods_id']]['pre_order_price']  = $row['pre_order_price'];//预购价格
        $arr[$row['goods_id']]['can_buy_num']      = $row['pre_order_num']>$row['goods_number']?$row['goods_number']:$row['pre_order_num']; //可购买数量
        $arr[$row['goods_id']]['surplus_num']      = (($row['pre_order_num']>$row['goods_number']?$row['goods_number']:$row['pre_order_num'])/$row['pre_order_num'])*$row['buy_number']; //剩余数量
        $arr[$row['goods_id']]['is_attr']          = empty($row['goods_attr_id'])?0:1;
        $arr[$row['goods_id']]['pre_order_id']     = $row['pre_order_id'];
    }
    return $arr;
}

?>
